import { axios as request  } from "@/utils/request";

export function getList({params}) {
  return request({
    url: 'api/role',
    method: 'get',
    params
  })
}

export default {
  getRoleList(params) {
    return request({
      url: 'api/role/all',
      method: 'get',
      params: params
    })
  },
  addRole(params) {
    return request({
      url: 'api/role',
      method: 'post',
      data: params
    })
  },
  updataRole(params) {
    return request({
      url: 'api/role',
      method: 'put',
      data: params
    })
  },
  deleteRole(codeId) {
    return request({
      url: "api/role/" + codeId,
      method: "DELETE"
    });
  },
  //根据角色ID查询用户
  findUser(id) {
    return request({
      url: `api/role/${id}/user`,
      method: 'get',
    })
  },
  //保存分配用户
  updataUser(params) {
    return request({
      url: `api/role/${params.id}/user`,
      method: 'post',
      data:params.userIds
    })
  },
  //移除用户 /api/role/{roleId}/{userId}
  deleteUser(codeId,id) {
    return request({
      url: "api/role/" + codeId+"/"+id,
      method: "DELETE"
    });
  },
  //根据角色ID查询菜单
  findMenu(id) {
    return request({
      url: `api/role/${id}/menus`,
      method: 'get',
    })
  },
  //获取用户，不包含角色 /
  findNoRoleUser(id) {
    return request({
      url: `api/role/${id}/exclusive-user`,
      method: 'get',
    })
  },
  //保存权限 /api/role/{id}/menu
  updataAuth(params) {
    return request({
      url: `api/role/${params.id}/menu`,
      method: 'put',
      data:params.menuIds
    })
  },
};